package com.gitee.sparta.core.bean.cluster;

import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;

import java.util.Objects;

/**
 * <p>
 *      从节点信息 bean
 * </p>
 *
 * @author zyred
 * @since v 0.0.2
 */
@Setter
@Getter
@Accessors(chain = true)
public class ServerBean {

    /** 服务注册编号 **/
    private int serverId;

    /** 服务启动选举的 端口号 **/
    private int serverPort;

    /** 服务的 IP 地址 **/
    private String serverIp;

    /** 是否是 leader 节点**/
    private boolean leader;

    /** 隔离信息 **/
    private String isolation;

    /** 多个 leader 出现的情况，其中只能有一个候选者 **/
    private boolean candidate;

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        ServerBean that = (ServerBean) o;
        return serverId == that.serverId
                && leader == that.leader
                && candidate == that.candidate
                && Objects.equals(serverPort, that.serverPort)
                && Objects.equals(serverIp, that.serverIp)
                && Objects.equals(isolation, that.isolation);
    }

    @Override
    public int hashCode() {
        return Objects.hash(serverId, leader, candidate,  serverPort, serverIp, isolation);
    }
}
